package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.Form.SearchForm;
import com.example.demo.entity.DoAlertDO;
import com.example.demo.mapper.DoAlertMapper;
import com.example.demo.service.DoAlertService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Emma
 * @since 2023-02-15
 */
@Service
public class DoAlertServiceImpl extends ServiceImpl<DoAlertMapper, DoAlertDO> implements DoAlertService {
    @Autowired
    private DoAlertMapper doAlertMapper;

    @Override
    public List<DoAlertDO> listByForm(SearchForm searchForm) {
        List<DoAlertDO> endList = new ArrayList<>();
        if(searchForm.getId()==null && searchForm.getMonitorType()==null
                && searchForm.getProcessDefId()==null && searchForm.getTarget()==null
                && searchForm.getTableId()==null && searchForm.getTaskInstanceId()==null ){
            //若查询关键字为空
            endList = this.doAlertMapper.selectList(null);
        }
        else{
            QueryWrapper<DoAlertDO> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq(searchForm.getId()!=null,"id",searchForm.getId())
                    .eq(searchForm.getTableId()!=null,"table_id",searchForm.getTableId())
                    .eq(searchForm.getTarget()!=null,"target", searchForm.getTarget())
                    .eq(searchForm.getMonitorType()!=null,"monitor_type",searchForm.getMonitorType())
                    .eq(searchForm.getProcessDefId()!=null,"process_def_id",searchForm.getProcessDefId())
                    .eq(searchForm.getTaskInstanceId()!=null,"task_instance_id",searchForm.getTaskInstanceId());
            endList = this.doAlertMapper.selectList(queryWrapper);
        }
        return endList;
    }
}
